package org.example.spark.rddcreate

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @ClassName RDDCreate.java
 * @author ylr
 * @version 1.0.0
 * @Description TODO
 * @createTime 2022年05月10日 13:40:00
 */
object RDDCreate {


  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("spark")
    val sc = new SparkContext(sparkConf)
    val rdd1 = sc.parallelize(List(1, 3, 5, 2, 4, 6))
    val rdd2 = sc.makeRDD(List(1, 3, 5, 2, 4, 6))
    rdd1.collect().foreach(x => println(x))
    rdd2.collect().foreach(x => println(x))
    // 从外部存储读取如file,hdfs,hbase
    val rdd3: RDD[String] = sc.textFile("input/word.txt")
    rdd3.collect().foreach(x=>println(x))

    sc.stop()
  }
}
